<?php

require_once("Model/UserHandler.php");

class UserView 
{
	//Privata strängar
	private $getUserName = "UserName";
	private $getPassword = "Password";
	private $getRepeatedPassword = "RepeatedPassword";
	private $getSubmit = "Register";
	
	//Konstanter
	const REGISTER_CTRL_HEADER = 1;
	const ERROR_USER_EXISTS = 2;
	const USER_ADDED_SUCCESS = 3;
	
	//Renderar rubriker
	public function RenderHeader($header)
	{
		switch($header)
		{
			case self::REGISTER_CTRL_HEADER;
				return "<h2>Register new user</h2>";
				break;												
		}			
	}	

	//Renderar meddelanden
	public function RenderMessage($message)
	{
		switch($message)
		{
			case self::ERROR_USER_EXISTS;
				return "FEL: " . $this->GetUserName() . " är upptaget.";
				break;
			case self::USER_ADDED_SUCCESS;
				return "Användaren " . $this->GetUserName() . " har registrerats";
				break;	
		}
	}			

	public function RenderErrorArray($errorArray)
	{
		$ret = NULL;
		foreach($errorArray as $error)
		{
			$ret .= $error . "</br>";
		}					
		return $ret;		
	}
	//Retunerar ett registreringsformulär
	public function RenderRegForm() 
	{
	    return $RegisterForm = 

	    "<form name='frmRegUser' id='frmRegUser' method='post'>	    		
			<p>Name:</p>			
			<input type='text' name='$this->getUserName' id='RegName' size='50' /><br/>
			<p>Password:</p>							
			<input type='password' name='$this->getPassword' id='RegPassword' size='50' /><br/> 	
			<p>Repeat password:</p>							
			<input type='password' name='$this->getRepeatedPassword' id='RepPassword' size='50' /><br/>					
			
			<input type='submit' value='Register' name='$this->getSubmit' id='Register' />	
					  			
		</form>";
	}
	
	public function RenderUserList() 
	{
	    return NULL;
	}

	public function RenderDeleteButton() 
	{
		return NULL;		
	}	
	
	//Retunerar användarnamnet
	public function GetUserName() 
	{	  	
		if (isset($_POST[$this->getUserName]) == TRUE)
		{				 		
			return $_POST[$this->getUserName];
		}
		
		return NULL;		
	}
	
	//Retunerar lösenordet 
	public function GetPassword() 
	{	
		if (isset($_POST[$this->getPassword]) == TRUE)
		{
			return $_POST[$this->getPassword];
		}
				
		return NULL;			
	}

	//Retunerar det repeterade lösenordet	
	public function GetRepeatedPassword() 
	{	
		if (isset($_POST[$this->getRepeatedPassword]) == TRUE)
		{
			return $_POST[$this->getRepeatedPassword];
		}
				
		return NULL;			
	}	

	//Retunerar TRUE om man tryckt på Register knappen.	
	public function TriedToRegister() 
	{	
		if (isset($_POST[$this->getSubmit]))
		{   			
			return TRUE;  	
		}
				
		return FALSE;
	   		
	}		
				       	
} 
  

?>
  